#include "BaseTreeTest.h"
#include "ui_BaseTreeTest.h"

BaseTreeTest::BaseTreeTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BaseTreeTest)
{
    ui->setupUi(this);
    //随机测试数据
    int colunmCount=qrand()%10+3;
    int rowCount=qrand()%1000+1;
//    //设置测试列
//    for(int i=0;i<colunmCount;i++)
//    {
//        ui->treeView_TestTree->addColumn("列"+QString::number(i+1));
//    }
    ui->treeView_TestTree->setColumnCount(colunmCount);
    ui->treeView_TestTree->setCheckable(true);
    //添加测试行
    for(int i=0;i<rowCount;i++)
    {
        QVector<QVariant> rowData;
        for(int j=0;j<colunmCount;j++)
        {
            rowData<<QString("行%1列%2").arg(i+1).arg(j+1);
        }
        testDataMap.insert(i+1,rowData);
        int parentId=0;
        if(i>=10&&i<100)
        {
            parentId=qrand()%10;
        }
        else if(i>=100)
        {
            parentId=qrand()%(100-10)+10;
        }
        ui->treeView_TestTree->addRowData(i+1,rowData,parentId);
    }
    //添加测试关联
    connect(ui->treeView_TestTree,&GY_IdTreeView::selectCellChangeSignal,[&](const QVariant &rowId,const int columnIndex)
    {
        QVariant data=ui->treeView_TestTree->getCellData(rowId,columnIndex);
        ui->lineEdit_EditValue->setText(data.toString());
    });
}

BaseTreeTest::~BaseTreeTest()
{
    delete ui;
}

void BaseTreeTest::on_pushButton_EditValue_clicked()
{
     ui->treeView_TestTree->setCellText(ui->treeView_TestTree->getSelectRowId(),ui->treeView_TestTree->getSelectCellColunmIndex(),ui->lineEdit_EditValue->text());
}

void BaseTreeTest::on_pushButton_AddColunm_clicked()
{
    ui->treeView_TestTree->addColumn("新建列");
}

void BaseTreeTest::on_pushButton_DeleteColunm_clicked()
{
    ui->treeView_TestTree->deleteColumn(ui->treeView_TestTree->getSelectCellColunmIndex());
}

void BaseTreeTest::on_pushButton_InsterColunm_clicked()
{
    ui->treeView_TestTree->insertColumn(ui->treeView_TestTree->getSelectCellColunmIndex(),"插入列");
}

void BaseTreeTest::on_pushButton_DeleteRow_clicked()
{
     ui->treeView_TestTree->deleteRow(ui->treeView_TestTree->getSelectRowId());
}
